package com.test.qpbgboot.base.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "返回状态码")
    private Integer code;
    @ApiModelProperty(value = "返回状态信息")
    private String msg;
    @ApiModelProperty(value = "返回数据")
    private Object data;

    public JsonResult(Integer code,String msg) {
        this.code=code;
        this.msg=msg;
    }

    public JsonResult(ResultStatus status) {
        this(status.getCode(),status.getMsg());
    }

    public JsonResult(ResultStatus status, Object data) {
        this(status);
        this.data=data;
    }

    public static JsonResult success() {
        return new JsonResult(ResultStatus.SUCCESS);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(ResultStatus.SUCCESS,data);
    }

    public static JsonResult failure() {
        return new JsonResult(ResultStatus.FAILURE);
    }

    public static JsonResult failure(Object data) {
        return new JsonResult(ResultStatus.FAILURE,data);
    }
}
